/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "pch.h"
#include "块代码解析.h"


std::vector<std::u16string> f_括号域(std::vector<std::u16string>::iterator& it
    , std::vector<std::u16string>::iterator& end
    , const std::u16string& 括号s
    , const std::u16string& 括号e
    ){
    int32 深度 = 0;
    std::vector<std::u16string> 代码块;
    while(it != end){
        if(*it == 括号s){
            ++深度;
        }
        else if(*it == 括号e){
            --深度;
        }
        else {
            代码块.emplace_back(*it);
        }
        ++it;
        
        if(深度 <= 0){
            break;
        }
    }
    return 代码块;
}

std::vector<std::u16string_view> f_符号分割(std::vector<std::u16string>::iterator& it
    , std::vector<std::u16string>::iterator& end
    , const std::u16string& 符号
    ) {

    std::vector<std::u16string_view> 分割文本;
    
    for(; it != end; ++it){
        if(*it == ","){
            continue;
        }else{
            分割文本.emplace_back(*it);
        }
    }
    return 分割文本;
}

std::vector<std::u16string_view> f_代码切片(std::vector<std::u16string>::iterator& it
    , std::vector<std::u16string>::iterator& end
    , const std::u16string& 结束符
    ) {
    
    std::vector<std::u16string_view> 切片;
    for(; it != end; ++it){
        if(*it == 结束符) {
            ++it; break;
        }
        切片.emplace_back(*it);
    }
    return 切片;
}

void f_符号分割(std::vector<std::u16string_view>& str
    , const std::u16string& 分割符
){
    /*for(auto& e : str){
        if(e != 分割符){

        }
    }*/
    for(auto& e : str){
		e.erase(std::remove_if(e.begin(), e.end(), [](const std::u16string_view& c) {
        	return c == 分割符;
    	}), e.end());
	}
}

